package framework;

import org.newdawn.slick.Animation;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.SpriteSheet;

public class Bird extends BasicEntity {
	
	private SpriteSheet sprite;
	
	Animation anim;
	
	private int distance;
	
	private int lastChange;
	
	private int nextChange;
	
	public Bird() {
		setXspeed(600);
		setYspeed(300);
		distance = 0;
		lastChange = 0;
		nextChange = Util.randomize(100, 500);
		setWidth(100);
		setHeight(42);
		try {
			sprite = new SpriteSheet(C.ASSETS_FOLDER + "bird.png", 120, 50);
		} catch (SlickException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		Image[] frames = new Image[2];
		frames[0] = sprite.getSprite(0, 0);
		frames[1] = sprite.getSprite(2, 0);
		anim = new Animation(frames, 100);
	}

	@Override
	public void draw(Graphics g) {
		anim.draw(getX(), getY(), getWidth(), getHeight());
	}

	@Override
	public void update(GameContainer gc, int delta) {
		super.update(gc, delta);
		distance += Math.abs(getStepXSpeed(delta));
		if (distance > lastChange + nextChange) {
			setYspeed(-300);
			lastChange = distance;
			nextChange = (int) (Util.randomize(100, 500) * getScale());
		}
	}	
}
